package com.example.shop_2211.fgViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntityResult
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CategoryViewModel:BaseViewModel() {
    val success = MutableLiveData<CategoryEntityResult>()
    val fail = MutableLiveData<String>()
    fun category(){
        viewModelScope.launch {
            try {
                success.value = apiService.category()
            }catch (e:Exception){
                fail.value = e.message
            }
        }
    }
    val searchSuccess = MutableLiveData<GoodsEntityResult>()
    val searchFail = MutableLiveData<String>()
    fun search(cid:Int, keyword:String, limit:Int,
               news:Boolean, page:Int,
               priceOrder:String,salesOrder:String){
        viewModelScope.launch {
            try {
                searchSuccess.value = apiService.search(cid, keyword, limit, news, page, priceOrder, salesOrder)
            }catch (e:Exception){
                searchFail.value = e.message
            }
        }
    }
}